Current File : //usr/lib/python3/dist-packages/twisted/spread/test/__pycache__/test_pbfailure.cpython-312.pyc
�

Ϫ�f�9����dZddlmZddlmZddlmZddlmZddl	m
Z
mZmZddl
mZddlmZGd	�d
e�ZGd�de�ZGd
�dej(�ZGd�dej(�ZGd�de
j.ej(ej0�ZGd�dej(ej0�Zej6ee�ej6ee�ej8j;e�Gd�dej<�ZGd�dej@�Z!Gd�dejD�Z#Gd�de#�Z$Gd�de$�Z%Gd�d �Z&Gd!�d"ejD�Z'y#)$z!
Tests for error handling in PB.
�)�StringIO)�defer)�log)�qual)�flavors�jelly�pb)�connectedServerAndClient)�unittestc��eZdZdZy)�AsynchronousExceptionz�
    Helper used to test remote methods which return Deferreds which fail with
    exceptions which are not L{pb.Error} subclasses.
    N��__name__�
__module__�__qualname__�__doc__���D/usr/lib/python3/dist-packages/twisted/spread/test/test_pbfailure.pyr
r
���rr
c��eZdZdZy)�SynchronousExceptionzm
    Helper used to test remote methods which raise exceptions which are not
    L{pb.Error} subclasses.
    Nrrrrrrrrrc��eZdZdZy)�AsynchronousErrorz�
    Helper used to test remote methods which return Deferreds which fail with
    exceptions which are L{pb.Error} subclasses.
    Nrrrrrr"rrrc��eZdZdZy)�SynchronousErrorzi
    Helper used to test remote methods which raise exceptions which are
    L{pb.Error} subclasses.
    Nrrrrrr)rrrc��eZdZy)�
JellyErrorN�rrrrrrrr0���rrc��eZdZy)�
SecurityErrorNrrrrr"r"4r rr"c�R�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
d�Zd
d�Z
y
)�
SimpleRootc�>�tjtd��S)zD
        Fail asynchronously with a non-pb.Error exception.
        zremote asynchronous exception)r�failr
��selfs r�remote_asynchronousExceptionz'SimpleRoot.remote_asynchronousException?s���z�z�/�0O�P�Q�Qrc��td��)zC
        Fail synchronously with a non-pb.Error exception.
        zremote synchronous exception)rr's r�remote_synchronousExceptionz&SimpleRoot.remote_synchronousExceptionEs��#�#A�B�Brc�>�tjtd��S)z@
        Fail asynchronously with a pb.Error exception.
        zremote asynchronous error)rr&rr's r�remote_asynchronousErrorz#SimpleRoot.remote_asynchronousErrorKs���z�z�+�,G�H�I�Irc��td��)z?
        Fail synchronously with a pb.Error exception.
        zremote synchronous error)rr's r�remote_synchronousErrorz"SimpleRoot.remote_synchronousErrorQs���9�:�:rc�D�Gd�dtj�}|d��)z>
        Fail with error that is not known to client.
        c��eZdZy)�4SimpleRoot.remote_unknownError.<locals>.UnknownErrorNrrrr�UnknownErrorr2\s��rr3zI'm not known to client!)r	�Error)r(r3s  r�remote_unknownErrorzSimpleRoot.remote_unknownErrorWs ��
	�2�8�8�	��5�6�6rc�$�|j�y�N)�
raiseJellyr's r�remote_jellyzSimpleRoot.remote_jellyas�����rc�$�|j�yr7)�
raiseSecurityr's r�remote_securityzSimpleRoot.remote_securityds�����rc��tj�}|j|j�|j	d�|Sr7)r�Deferred�addCallbackr8�callback�r(�ds  r�remote_deferredJellyzSimpleRoot.remote_deferredJellygs/���N�N���	�
�
�d�o�o�&�	�
�
�4���rc��tj�}|j|j�|j	d�|Sr7)rr>r?r;r@rAs  r�remote_deferredSecurityz"SimpleRoot.remote_deferredSecurityms1���N�N���	�
�
�d�(�(�)�	�
�
�4���rNc��td��)NzI'm jellyable!)r�r(�resultss  rr8zSimpleRoot.raiseJellyss���)�*�*rc��td��)NzI'm secure!)r"rGs  rr;zSimpleRoot.raiseSecurityvs
���M�*�*rr7)rrrr)r+r-r/r5r9r<rCrEr8r;rrrr$r$>s<��R�C�J�;�7�����+�+rr$c��eZdZdZdZd�Zy)�SaveProtocolServerFactoryzd
    A L{pb.PBServerFactory} that saves the latest connected client in
    C{protocolInstance}.
    Nc��||_y)z3
        Keep track of the given protocol.
        N)�protocolInstance)r(�protocols  r�clientConnectionMadez.SaveProtocolServerFactory.clientConnectionMade�s��!)��r)rrrrrMrOrrrrKrKzs���
��)rrKc��eZdZdZd�Zy)�PBConnTestCaserc����tt���_�j�j_t	j
��_t�fd��fd��\�_�_	�_
y)Nc�:���jjd�Sr7)�
serverFactory�
buildProtocolr's�r�<lambda>z&PBConnTestCase.setUp.<locals>.<lambda>�����D�&�&�4�4�T�:�rc�:���jjd�Sr7)�
clientFactoryrUr's�rrVz&PBConnTestCase.setUp.<locals>.<lambda>�rWr)rKr$rT�unsafeTracebacksr	�PBClientFactoryrYr
�connectedServer�connectedClient�pumpr's`r�setUpzPBConnTestCase.setUp�s]���6�z�|�D���.2�.C�.C����+��/�/�1���

%�:�:�
�		
�� �� ��IrN)rrrrZr_rrrrQrQ�s
����
rrQc��eZdZejj
Zd�Zd�Zd�Z	d�Z
d�Zd�Zd�Z
dd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zy)�PBFailureTestsc����������fd���jj�}��fd�}|j|��jj	�y)Nc���|j���j|jd��r,�j��}�j	t|�d�|j|j|jfS)N�Traceback unavailable
�)�trap�compare�	traceback�flushLoggedErrors�assertEqual�len�type�value)�err�errs�
exceptionType�flushr(s  ���r�ebz)PBFailureTests._exceptionTest.<locals>.eb�sb����H�H�]�#��L�L����(A�B���-�-�m�<��� � ��T��A�.��H�H�c�i�i����7�7rc�L��|j��}|j��|Sr7)�
callRemote�
addErrback)�rootrBrr�methods  ��r�
gotRootObjectz4PBFailureTests._exceptionTest.<locals>.gotRootObject�s"�������'�A�
�L�L����Hr�rY�
getRootObjectr?r^rq)r(rwrprqrBrxrrs````  @r�_exceptionTestzPBFailureTests._exceptionTest�s?���	8�
���,�,�.��	�
	
�
�
�m�$��	�	���rc�0�|jdtd�S)z�
        Test that a Deferred returned by a remote method which already has a
        Failure correctly has that error passed back to the calling side.
        �asynchronousExceptionT)r{r
r's r�test_asynchronousExceptionz)PBFailureTests.test_asynchronousException�s��
�"�"�#:�<Q�SW�X�Xrc�0�|jdtd�S)zw
        Like L{test_asynchronousException}, but for a method which raises an
        exception synchronously.
        �synchronousExceptionT)r{rr's r�test_synchronousExceptionz(PBFailureTests.test_synchronousException�s��
�"�"�#9�;O�QU�V�Vrc�0�|jdtd�S)z�
        Like L{test_asynchronousException}, but for a method which returns a
        Deferred failing with an L{pb.Error} subclass.
        �asynchronousErrorF)r{rr's r�test_asynchronousErrorz%PBFailureTests.test_asynchronousError�s��
�"�"�#6�8I�5�Q�Qrc�0�|jdtd�S)z}
        Like L{test_asynchronousError}, but for a method which synchronously
        raises a L{pb.Error} subclass.
        �synchronousErrorF)r{rr's r�test_synchronousErrorz$PBFailureTests.test_synchronousError�s��
�"�"�#5�7G��O�Orc�*�|j||�|Sr7)rj)r(�result�expectedResults   r�_successzPBFailureTests._success�s�������0��
rc�D�|j|j||f��|S)N)�callbackArgs)�addCallbacksr�)r(�
remoteCallr�rrs    r�_addFailingCallbacksz#PBFailureTests._addFailingCallbacks�s$������
�
�r��@Q��R��rNc��������jj�}�����fd�}|j|��jj	�y)z�
        Call the given remote method and attach the given errback to the
        resulting Deferred.  If C{exc} is not None, also assert that one
        exception of that type was logged.
        c�~���j|j�����}����fd�}|j|�|S)Nc�\���jt�j���d�|S)Nre)rjrkri)rn�excr(s ��r�
gotFailurez@PBFailureTests._testImpl.<locals>.gotRootObj.<locals>.gotFailure�s(����$�$�S��)?�)?��)D�%E�q�I��Jr)r�rt�addBoth)�obj�failureDeferredr�rrr��expectedrwr(s   �����r�
gotRootObjz,PBFailureTests._testImpl.<locals>.gotRootObj�sE���"�7�7����v�&��"��O���� �'�'�
�3�"�"rNry)r(rwr�rrr��rootDeferredr�s`````  r�	_testImplzPBFailureTests._testImpl�sA����)�)�7�7�9��	#�	#�	� � ��,��	�	���rc�4���fd�}�jdd|�S)z�
        Test that an exception which is a subclass of L{pb.Error} has more
        information passed across the network to the calling side.
        c���|jt��j|jt��j|j|j�y)N�+�rfr�assertNotIsInstancerl�str�assertIsInstancerm�r&r(s �r�failureJellyz6PBFailureTests.test_jellyFailure.<locals>.failureJelly�s>����I�I�j�!��$�$�T�Y�Y��4��!�!�$�*�*�d�i�i�8�rrr��r�)r(r�s` r�test_jellyFailurez PBFailureTests.test_jellyFailure�s���	��~�~�g�r�<�8�8rc�4���fd�}�jdd|�S)z�
        Test that a Deferred which fails with a L{pb.Error} is treated in
        the same way as a synchronously raised L{pb.Error}.
        c���|jt��j|jt��j|j|j�y)N�r�r�s �r�failureDeferredJellyzFPBFailureTests.test_deferredJellyFailure.<locals>.failureDeferredJellys>����I�I�j�!��$�$�T�Y�Y��4��!�!�$�*�*�d�i�i�8�r�
deferredJellyr�r�)r(r�s` r�test_deferredJellyFailurez(PBFailureTests.test_deferredJellyFailure�s���	��~�~�o�s�4H�I�Irc�4���fd�}�jdd|�S)z�
        A non-jellyable L{pb.Error} subclass raised by a remote method is
        turned into a Failure with a type set to the FQPN of the exception
        type.
        c�>���j|jd�y)Ns3twisted.spread.test.test_pbfailure.SynchronousError��rjrlr�s �r�failureUnjellyablezBPBFailureTests.test_unjellyableFailure.<locals>.failureUnjellyables �������	�	�Q�
�rr�r�r�)r(r�s` r�test_unjellyableFailurez&PBFailureTests.test_unjellyableFailures���	��~�~�0�#�7I�J�Jrc�4���fd�}�jdd|�S)z�
        Test that an exception which is a subclass of L{pb.Error} but not
        known on the client side has its type set properly.
        c�>���j|jd�y)Ns/twisted.spread.test.test_pbfailure.UnknownError��r�r�s �r�failureUnknownz:PBFailureTests.test_unknownFailure.<locals>.failureUnknowns �������	�	�M�
�r�unknownErrorr�r�)r(r�s` r�test_unknownFailurez"PBFailureTests.test_unknownFailures���	��~�~�n�d�N�C�Crc�4���fd�}�jdd|�S)z�
        Test that even if an exception is not explicitly jellyable (by being
        a L{pb.Jellyable} subclass), as long as it is an L{pb.Error}
        subclass it receives the same special treatment.
        c���|jt��j|jt��j|j|j�y)N���rfr"r�rlr�r�rmr�s �r�failureSecurityz<PBFailureTests.test_securityFailure.<locals>.failureSecurity,s>����I�I�m�$��$�$�T�Y�Y��4��!�!�$�*�*�d�i�i�8�r�securityr�r�)r(r�s` r�test_securityFailurez#PBFailureTests.test_securityFailure%s���	��~�~�j�$��@�@rc�4���fd�}�jdd|�S)z�
        Test that a Deferred which fails with a L{pb.Error} which is not
        also a L{pb.Jellyable} is treated in the same way as a synchronously
        raised exception of the same type.
        c���|jt��j|jt��j|j|j�y)N�r�r�s �r�failureDeferredSecurityzEPBFailureTests.test_deferredSecurity.<locals>.failureDeferredSecurity;s>����I�I�m�$��$�$�T�Y�Y��4��!�!�$�*�*�d�i�i�8�r�deferredSecurityr�r�)r(r�s` r�test_deferredSecurityz$PBFailureTests.test_deferredSecurity4s���	��~�~�0�%�9P�Q�Qrc�>���fd�}�jdd|t�S)z�
        Test that attempting to call a method which is not defined correctly
        results in an AttributeError on the calling side.
        c�|��|jtj��j|jd�y)Nrd��)rfr	�NoSuchMethodrgrhr�s �r�
failureNoSuchz>PBFailureTests.test_noSuchMethodFailure.<locals>.failureNoSuchIs)����I�I�b�o�o�&��L�L����)B�C�r�nosuchr�)r��AttributeError)r(r�s` r�test_noSuchMethodFailurez'PBFailureTests.test_noSuchMethodFailureCs���	�
�~�~�h��}�n�M�Mrc�����jj�}d�}|j|��fd�}|j|��jj�y)z�
        Test that a copied failure received from a PB call can be logged
        locally.

        Note: this test needs some serious help: all it really tests is that
        log.err(copiedFailure) doesn't raise an exception.
        c�$�|jd�S)Nr�)rt)�rootObjs r�	connectedz;PBFailureTests.test_copiedFailureLogging.<locals>.connectedZs���%�%�&<�=�=rc���tj|��jt�}�j	t|�d�y)N�)rrnrirrjrk)�failureror(s  �r�	exceptionz;PBFailureTests.test_copiedFailureLogging.<locals>.exception_s4����G�G�G���)�)�*>�?�D����S��Y��*rN)rYrzr?rur^rq)r(rBr�r�s`   r�test_copiedFailureLoggingz(PBFailureTests.test_copiedFailureLoggingPsM���
���,�,�.��	>�	
�
�
�i� �	+�
	
���Y���	�	���rc�J���tjtd��}tjtj|t����}g���fd�}|�}|j
d��jt|j|��jt��d��d}�j|jtt�jd���j|jd��j|j d	�y)
z�
        L{pb.CopiedFailure.throwExceptionIntoGenerator} will throw a
        L{RemoteError} into the given paused generator at the point where it
        last yielded.
        �foo��invokerc3��K�	d���jd�y#tj$r}�j|�Yd}~yd}~wwxYw�w)NzRemoteError not raised)r&r	�RemoteError�append)r�r�r(s ��r�
generatorFunczFPBFailureTests.test_throwExceptionIntoGenerator.<locals>.generatorFuncqsF�����
4��
��	�	�2�3���>�>�
&�� � ��%�%��
&�s)�A��A�A	�A�A�A	�	ANrer�ascii)r�rd)r	�CopyableFailurer�r�unjelly�DummyInvoker�send�assertRaises�
StopIteration�throwExceptionIntoGeneratorrjrk�
remoteTyper�encode�args�remoteTraceback)r(�original�copyr��genr�r�s`     @r� test_throwExceptionIntoGeneratorz/PBFailureTests.test_throwExceptionIntoGeneratorgs�����%�%�n�U�&;�<���}�}�U�[�[��<�>�J�K���	�	4��o����������-��)I�)I�3�O�����Y���+���l���������n�)=�)D�)D�W�)M�N�������8�,�����,�,�.G�Hrr7)rrrr�TestCaserjrgr{r~r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrara�ss�����+�+�G��&Y�W�R�P����09�J�
K�D�
A�
R�N��.Irrac�<�eZdZejj
ZdZy)�PBFailureUnsafeTestsreN)rrrrr��failIfEqualsrgrZrrrr�r��s�����,�,�G��rr�c��eZdZdZdZy)r�zZ
    A behaviorless object to be used as the invoker parameter to
    L{jelly.jelly}.
    N)rrrr�serializingPerspectiverrrr�r��s���
"�rr�c�"�eZdZdZd�Zd�Zd�Zy)�FailureJellyingTestsz:
    Tests for the interaction of jelly and failures.
    c���tjt��}|j|j	t�t�|j|j	t
�t
�t
jt
j|t����}|j|j	t�t�|j|j	t
�t
�y)z�
        An unjellied L{CopyableFailure} has a check method which behaves the
        same way as the original L{CopyableFailure}'s check method.
        r�N�	r	r��ZeroDivisionError�assertIs�check�ArithmeticErrorrr�r�)r(r��copieds   r�test_unjelliedFailureCheckz/FailureJellyingTests.test_unjelliedFailureCheck�s���
�%�%�&7�&9�:���
�
�h�n�n�%6�7�9J�K��
�
�h�n�n�_�5��G����u�{�{�8�\�^�L�M���
�
�f�l�l�#4�5�7H�I��
�
�f�l�l�?�3�_�Erc�x�tjt��}|j|j	t�t�|j|j	t
�t
�t
jt
j|t����}tj|�}t
jt
j|t����}|j|j	t�t�|j|j	t
�t
�y)aX
        The object which results from jellying a L{CopyableFailure}, unjellying
        the result, creating a new L{CopyableFailure} from the result of that,
        jellying it, and finally unjellying the result of that has a check
        method which behaves the same way as the original L{CopyableFailure}'s
        check method.
        r�Nr�)r(r��
copiedOnce�
derivative�copiedTwices     r�test_twiceUnjelliedFailureCheckz4FailureJellyingTests.test_twiceUnjelliedFailureCheck�s����%�%�&7�&9�:���
�
�h�n�n�%6�7�9J�K��
�
�h�n�n�_�5��G��]�]�5�;�;�x���#P�Q�
��'�'�
�3�
��m�m�E�K�K�
�L�N�$S�T���
�
�k�'�'�(9�:�<M�N��
�
�k�'�'��8�/�Jrc�Z�tjtd��}tjtj|t����}t
�}|j|�tt�}dj|�}|j||j��y)a
        When L{CopiedFailure.printTraceback} is used to print a copied failure
        which was unjellied from a L{CopyableFailure} with C{unsafeTracebacks}
        set to C{False}, the string representation of the exception value is
        included in the output.
        zsome reasonr�z.Traceback from remote host -- {}: some reason
N)r	r��	Exceptionrr�r�r�printTracebackr�formatrj�getvalue)r(r�r��outputr��expectedOutputs      r� test_printTracebackIncludesValuez5FailureJellyingTests.test_printTracebackIncludesValue�s~���%�%�i�
�&>�?�����u�{�{�8�\�^�L�M��������f�%���O�	�M�T�T��
��	
�������):�;rN)rrrrr�rrrrrr�r��s���
F�K�"<rr�N)(r�ior�twisted.internetr�twisted.pythonr�twisted.python.reflectr�twisted.spreadrrr	�twisted.test.iosimr
�
twisted.trialrrr
rr4rr�	Jellyable�
RemoteCopyrr"�setUnjellyableForClass�globalSecurity�allowInstancesOf�Rootr$�PBServerFactoryrKr�rQrar�r�r�rrr�<module>rs8����"��'�-�-�7�"�
�I���9��������r�x�x��	��"�"�B�H�H�b�m�m�	�	�B�H�H�b�m�m�	�����*�j�1�����-��7����"�"�=�1�9+����9+�x)�� 2� 2�)�
�X�&�&�
�"fI�^�fI�R�>��
"�"�1<�8�,�,�1<r
Page Not Found
Parece que el enlace que apuntaba aquí no sirve. ¿Quieres probar con una búsqueda?
¡Hola!